#!/bin/bash
# random.sh
#
# Gives a random number between a min and max number
# and divisible by another one

# Not enough arguments (< or > 3)
if [ $# -ne 3 ]; then
	echo "Usage: $0 MIN MAX DIV_BY"
	exit 1
fi

FLOOR=$1
RANGE=$2
DIV_BY=$3

# Start off with 0
number=0
while [ "$number" -le $FLOOR ]
do		
	let res=$number%=$DIV_BY
	
	until [ $res -ne 0 ]
	do
  		number=$RANDOM
  		
  		let "number %= $RANGE"  # Scales $number down within $RANGE.
	done
done

echo "Random number between $FLOOR and $RANGE and divisible by $DIV_BY: $number"


exit 0
